﻿package mortal.game.view.forging.view.compound
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import flash.utils.*;
    import mortal.game.view.common.*;

    public class CompoundConfig extends Object
    {
        private var _compoundDic:Dictionary;
        private var _carogertTabData:Array;
        private static var _instance:CompoundConfig;

        public function CompoundConfig()
        {
            this._compoundDic = new Dictionary();
            this._carogertTabData = [];
            if (_instance != null)
            {
                throw new Error(" CompoundConfig 单例 ");
            }
            this.init();
            return;
        }// end function

        private function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("t_compound_config.json");
            this.write(_loc_1);
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_2:TCompoundConfig = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            for each (_loc_4 in param1)
            {
                
                _loc_2 = new TCompoundConfig();
                ClassTypesUtil.copyValue(_loc_2, _loc_4);
                if (this._compoundDic[_loc_2.type] == null)
                {
                    this._compoundDic[_loc_2.type] = new Array();
                    _loc_3 = {label:_loc_2.typeName, type:_loc_2.type};
                    this._carogertTabData.push(_loc_3);
                }
                (this._compoundDic[_loc_2.type] as Array).push(_loc_2);
            }
            this._carogertTabData.sort(this.sortTab);
            return;
        }// end function

        private function sortTab(param1:Object, param2:Object) : int
        {
            if (param1.type > param2.type)
            {
                return 1;
            }
            if (param1.type < param2.type)
            {
                return -1;
            }
            return 0;
        }// end function

        public function get compoundDic() : Dictionary
        {
            return this._compoundDic;
        }// end function

        public function get carogertTabData() : Array
        {
            return this._carogertTabData;
        }// end function

        public static function get instance() : CompoundConfig
        {
            if (_instance == null)
            {
                _instance = new CompoundConfig;
            }
            return _instance;
        }// end function

    }
}
